import Taro from '@tarojs/taro';

// 小程序跳转
export default class TaroRouter {
    constructor({ subPackagesReg }) {
        this.subPackagesReg = subPackagesReg;
    }

    switchTab = options => {
        return Taro.switchTab(options);
    };
    forward = options => {
        // 检查分包路由
        if (options.url.match(this.subPackagesReg)) {
            options.url = options.url.replace('/pages', '/base');
        }
        return Taro.navigateTo(options);
    };
    back = options => {
        return Taro.navigateBack(options);
    };
    redirect = options => {
        return Taro.redirectTo(options);
    };
}
